<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>"><!-- jsp文件头和头部 -->
	<link rel="stylesheet" href="static/css/bootstrap.min.css" />
	<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css"  />
	<link rel="stylesheet" href="static/css/font-awesome.min.css" />
	<link rel="stylesheet" href="static/css/ace.min.css" />
	<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
	<link rel="stylesheet" href="static/css/ace-skins.min.css" />
	<link type="text/css" rel="stylesheet" href="plugins/zTree/2.6/zTreeStyle.css"/>
	<link rel="stylesheet" type="text/css" href="plugins/bootstrap/css/bootstrap-table.css" />
	</head>
<body>	
<div class="container-fluid" id="main-container">


<div id="page-content" class="clearfix">
						
  <div class="row-fluid">
  	
	<div id="officeTree" style="width:20%;background-color: #fff;float:left;border-radius: 5px; border:2px solid #438EB9; margin-top: 5px;">
		
		<div style="width: 100%;height:25px;font-size:16px;background-color:#438EB9;color:#fff; font-family:'微软雅黑';"><span style="margin-left:10px;padding-top: 10px;">组织机构</span></div>
		<ul id="tree" class="tree" style="overflow:auto;"></ul>
	</div>
	<div  style="width:78%;float:right;">
		<!-- 检索  -->
		<div style="margin-top: 10px;">
			<input id="sousuo" type="text" placeholder="搜索" > 
			<button class="btn btn-mini btn-light" onclick="sousuo();" title="检索" style="margin-top: -10px;margin-left: 10px;"><i id="nav-search-icon" class="icon-search"></i></button>
		</div>
		
		<table id="officetable" class="table table-striped table-bordered table-hover"></table>
		
		<div id="newAdd">
			<a class="btn btn-small btn-success" onclick="add();"style="border-radius: 0px;">新增</a>
			<a class="btn btn-small btn-success" onclick="location.reload()" style="border-radius: 0px;">刷新</a>
		</div>
	</div>
 
 
 
 
	<!-- PAGE CONTENT ENDS HERE -->
  </div><!--/row-->
	
</div><!--/#page-content-->
</div><!--/.fluid-container#main-container-->
		
		<!-- 引入 -->
		<script src="static/1.9.1/jquery.min.js"></script>
		<script src="static/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="static/js/jquery-ui-1.10.2.custom.min.js"></script>
		<script type="text/javascript" src="static/js/jquery.ui.touch-punch.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script>
		<script type="text/javascript" src="static/js/fuelux.spinner.js"></script>
		<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script>
		<script type="text/javascript" src="static/js/bootstrap-timepicker.min.js"></script>
		<script type="text/javascript" src="static/js/date.js"></script>
		<script type="text/javascript" src="static/js/daterangepicker.min.js"></script>
		<script type="text/javascript" src="static/js/bootstrap-colorpicker.min.js"></script>
		<script type="text/javascript" src="static/js/jquery.knob.min.js"></script>
		<script type="text/javascript" src="static/js/jquery.autosize-min.js"></script>
		<script type="text/javascript" src="static/js/jquery.inputlimiter.1.3.1.min.js"></script>
		<script type="text/javascript" src="static/js/jquery.maskedinput.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
		<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script><!-- 提示框  -->
		<!-- ace scripts -->
		<script src="static/js/ace-elements.min.js"></script>
		<script src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="plugins/zTree/2.6/jquery.ztree-2.6.min.js"></script>
		<script src="plugins/bootstrap/js/bootstrap-table.js"></script>
		<script src="plugins/bootstrap/js/bootstrap-table-zh-CN.js"></script>
		<script type="text/javascript">
		
		$(top.hangge());
		
		var zTree;
		<%-- var url = "<%=basePath%>office/treeData.do";
			$.get(url,function(data){
				
			}); --%>
		 $(document).ready(function(){
			$(document).keydown(function(event){ 
				if(event.keyCode==13){ 
					sousuo(); 
				}
			 });
			 $.ajax({
				url : "<%=basePath%>office/treeData.do",
				type : "post",
				async: false,
				 /* data : {
					'platformId' : stationId
				}, */ 
				dataType: 'json', 
			    success:function(data){
			    	var zTreeNodes=eval(data.zTreeNodes);
			    	var setting = {
			    		 callback: {
							click: zTreeOnClick
						},
					    showLine: true    
					};
					zTree = $("#tree").zTree(setting, zTreeNodes);
			    }
			 }); 
			
			/* var setting = {
			    showLine: true,
			    checkable: true
			};
			var zn = '${zTreeNodes}';
			var zTreeNodes = eval(zn);
			zTree = $("#tree").zTree(setting, zTreeNodes); */
		});
		
		function zTreeOnClick(event, treeId, treeNode) {
    			//alert(treeNode.tId + ", " + treeNode.name+ ", " +treeId);
    			var json=zTree.getNodeByTId(treeNode.tId);
    			var officeId=json.office_id;
    			$('#officetable').bootstrapTable('refresh',{
					url: '<%=basePath%>office/getClickOfficeData.do?officeId='+officeId,
					contentType: "application/x-www-form-urlencoded",
					// 数据绑定
					cache: false,
			        // 是否启用条纹风格
			        striped: true,
			        onlyInfoPagination:true
				});
				$("#officetable").on('load-success.bs.table',function(){
					$(".pagination-detail").hide();
					$("#newAdd").css("margin-top","20px");
				})
			}
			function sousuo(){
				var txt = $("#sousuo").val();
				//queryParams	: refreshParameters
				$('#officetable').bootstrapTable('refresh',{
					url: '<%=basePath%>office/getSearchList.do',
					method : 'post',
					contentType: "application/x-www-form-urlencoded",
					striped : true,
					dataType : "json",
					pagination : true,
					pageSize : 10,
					pageNumber : 1,
					sidePagination: "server",
					queryParamsType : "limit",
			        queryParams	: queryParams
				});
				$("#officetable").on('load-success.bs.table',function(){
					$(".pagination-detail").show();
				});
			}
			
			// 编辑事件
		    window.operateEvents = {
		        'click .edit': function (e, value, row, index) {
		        	// 设定URL
		            //var url = rootPath + "/sys/office/form?id="+row.id+"";
		           // window.location.href = url;
		        },
		        'click .delete': function (e, value, row, index) {        	
		        	Modal.confirm(
				    {
				        msg: "确定删除选中记录？"
				    })
				    .on( function (e) {
				        if(e) { // 确定删除
				        	// 设定URL
				        	//var url = rootPath + "/sys/office/delete?id="+row.id+"";
				           // window.location.href = url;
				        } 
				    });
		        }
		    };
			
			 // 操作加载样式
		    function operateFormatter(value, row, index) {
		    	//alert(row.office_id);
		        return [
		            '<a class="btn btn-mini btn-info" title="编辑" onclick="edit(\''+row.office_id+'\');"><i class="icon-edit"></i></a>&nbsp;&nbsp;',
					'<a class="btn btn-mini btn-danger" title="删除" onclick="del(\''+row.office_id+'\');"><i class="icon-trash"></i></a>'
		        ].join('');
		    }
			
		$('#officetable').bootstrapTable({
			  	url: '<%=basePath%>office/getOfficeList.do', 
				contentType: "application/x-www-form-urlencoded",
				// 数据绑定
				method : 'post',
				striped : true,
				dataType : "json",
				pagination : true,
				pageSize : 10,
				pageNumber : 1,
				sidePagination: "server",
				queryParamsType : "limit",
				queryParams	: queryParams,
				pageList : [10, 20],
			    columns: [
			   	{
		        	field: 'name',
		            title: '机构名称',
		            align: 'center',
		            valign: 'middle'
		        }, {
		        	field: 'areaName',
		            title: '归属区域',
		            align: 'center',
		            valign: 'top',
		            sortable: false
		        }, {
		        	field: 'code',
		            title: '机构编码',
		            align: 'center',
		            valign: 'top',
		            sortable: false
		        }, {
		        	field: 'type',
		            title: '机构类型',
		            align: 'center',
		            valign: 'middle',
		            sortable: false,
		            formatter: infoFormatter
		        }, {
		            title: '操作',
		            align: 'center',
		            valign: 'middle',
		            clickToSelect: false,
		            formatter: operateFormatter,
		            events: operateEvents
		        } ]
			});
		
			function queryParams(params) {
				return {
					size : params.limit,
					page : params.pageNumber,
					txt : $("#sousuo").val()
				};
			}
			
			function infoFormatter(value, row, index) {
		    	if(value==1){
		    		return "公司";
		    	}
		    	if(value==2){
		    		return "部门";
		    	}
		    	if(value==3){
		    		return "小组";
		    	}
		    	if(value==4){
		    		return "其他";
		    	}
		    }
		   
		    
		     
		    
		//检索
		function search(){
			top.jzts();
			$("#Form").submit();
		}
		
		//新增
		function add(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="新增";
			 diag.URL = '<%=basePath%>office/goAdd.do';
			 diag.Width = 450;
			 diag.Height = 475;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 if('${page.currentPage}' == '0'){
						 top.jzts();
						 setTimeout("self.location=self.location",100);
					 }else{
						 location.reload();//刷新页面
					 }
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//删除
		function del(Id){
			bootbox.confirm("确定要删除吗?", function(result) {
				if(result) {
					top.jzts();
					var url = "<%=basePath%>office/delete.do?OFFICE_ID="+Id+"&tm="+new Date().getTime();
					$.get(url,function(data){
						if("${page.currentPage}"==0){
						 	location.reload();
						 }else{
						 	alert("删除失败");
						 }
					});
				}
			});
		}
		
		//修改
		function edit(Id){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="编辑";
			 diag.URL = '<%=basePath%>office/goEdit.do?OFFICE_ID='+Id;
			 diag.Width = 450;
			 diag.Height = 475;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 //nextPage(${page.currentPage});
					 if("${page.currentPage}"==0){
					 	location.reload();
					 }else{
					 	alert("修改失败");
					 }
				}
				diag.close();
			 };
			 diag.show();
		}
		</script>
		
		<script type="text/javascript">
		
		$(function() {
			
			//下拉框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			
			//日期框
			$('.date-picker').datepicker();
			
			//复选框
			$('table th input:checkbox').on('click' , function(){
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function(){
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
					
			});
			
		});
		
		
		//批量操作
		function makeAll(msg){
			bootbox.confirm(msg, function(result) {
				if(result) {
					var str = '';
					for(var i=0;i < document.getElementsByName('ids').length;i++)
					{
						  if(document.getElementsByName('ids')[i].checked){
						  	if(str=='') str += document.getElementsByName('ids')[i].value;
						  	else str += ',' + document.getElementsByName('ids')[i].value;
						  }
					}
					if(str==''){
						bootbox.dialog("您没有选择任何内容!", 
							[
							  {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback": function() {
									//Example.show("great success");
									}
								}
							 ]
						);
						
						$("#zcheckbox").tips({
							side:3,
				            msg:'点这里全选',
				            bg:'#AE81FF',
				            time:8
				        });
						
						return;
					}else{
						if(msg == '确定要删除选中的数据吗?'){
							top.jzts();
							$.ajax({
								type: "POST",
								url: '<%=basePath%>office/deleteAll.do?tm='+new Date().getTime(),
						    	data: {DATA_IDS:str},
								dataType:'json',
								//beforeSend: validateData,
								cache: false,
								success: function(data){
									 $.each(data.list, function(i, list){
											nextPage("${page.currentPage}");
									 });
								}
							});
						}
					}
				}
			});
		}
		
		//导出excel
		function toExcel(){
			window.location.href='<%=basePath%>office/excel.do';
		}
		
		
		</script>
		
	</body>
</html>

